package lumis.portal.audit;

import lumis.portal.PortalException;
import lumis.portal.PortalObjectNotFoundException;
import lumis.portal.dao.hibernate.GenericHibernateDao;
import lumis.portal.transaction.PortalTransactionFactory;

/**
 * Data access object for {@link AuditCategory}.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
class AuditCategoryDao extends GenericHibernateDao<AuditCategory, String>
{
	protected AuditCategoryDao()
	{
		super(AuditCategory.class);
	}
	
	/**
	 * Returns the audit category with the given key.
	 * @param categoryKey	the aggregation type's key.
	 * @return the audit category.
	 * @throws PortalObjectNotFoundException if the audit category was not found.
	 * @since 6.0.0
	 */
	protected AuditCategory findByKey(String categoryKey) throws PortalException
	{
		AuditCategory auditCategory = (AuditCategory) getSession(PortalTransactionFactory.getCurrentTransaction())
														.getNamedQuery(AuditCategory.NAMED_QUERY_FIND_BY_KEY)
														.setParameter("key", categoryKey).uniqueResult();
		if (auditCategory == null)
		{
			throw new PortalObjectNotFoundException("AuditCategory with key '" + categoryKey + "' not found");
		}
		
		return auditCategory;
	}
}